package outoforder.leetcode;

import org.junit.Test;

/**
 * @author shhjiang_001
 * @create 2020-07-07 22:30
 */
//  打家劫舍2
public class Solution213 {
    public int rob(int[] nums) {
        if(nums.length == 0) return 0;
        if(nums.length == 1) return nums[0];
        int[] robBase1 = new int[nums.length - 1];
        int[] robBase2 = new int[nums.length - 1];
        for (int i = 0; i < nums.length - 1; i++) {
            robBase1[i] = nums[i] ;
            robBase2[i] = nums[i+1] ;
        }

        return Math.max(robMethod(robBase1),robMethod(robBase2));
    }
    public int robMethod(int[] nums) {
        int len = nums.length;
        int[][] dp = new int[len+1][2];
        for (int i = 1; i <= len; i++) {
            dp[i][0] = Math.max(dp[i-1][0],dp[i-1][1]);
            dp[i][1] = dp[i-1][0]+ nums[i-1];
        }

        return Math.max(dp[len][0],dp[len][1]);
    }
    @Test
    public void test(){
        System.out.println(rob(new int[]{1, 2, 3, 1}));
    }
}
